{% extends "base.html" %}
{% block title %}管理员仪表盘{% endblock %}

{% block content %}
<div class="d-flex justify-content-between mb-4">
    <h2><i class="bi bi-speedometer2"></i> 系统概览</h2>
    <div class="text-muted">最后更新: {{ now.strftime('%Y-%m-%d %H:%M') }}</div>
</div>

<div class="row mb-4">
    <div class="col-md-4">
        <div class="card card-counter bg-info text-white">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h5 class="card-title">客户总数</h5>
                        <p class="card-text display-6">{{ customer_count }}</p>
                    </div>
                    <i class="bi bi-people-fill" style="font-size: 3rem; opacity: 0.3;"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card card-counter bg-success text-white">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h5 class="card-title">银行卡总数</h5>
                        <p class="card-text display-6">{{ card_count }}</p>
                    </div>
                    <i class="bi bi-credit-card" style="font-size: 3rem; opacity: 0.3;"></i>
                </div>
            </div>
        </div>
    </div>
    <div class="col-md-4">
        <div class="card card-counter bg-warning text-dark">
            <div class="card-body">
                <div class="d-flex justify-content-between align-items-center">
                    <div>
                        <h5 class="card-title">总存款金额</h5>
                        <p class="card-text display-6">¥{{ "%0.2f"|format(total_balance) }}</p>
                    </div>
                    <i class="bi bi-cash-stack" style="font-size: 3rem; opacity: 0.3;"></i>
                </div>
            </div>
        </div>
    </div>
</div>

<div class="card">
    <div class="card-header bg-primary text-white">
        <h3 class="mb-0"><i class="bi bi-clock-history"></i> 最近交易记录</h3>
    </div>
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-hover">
                <thead class="table-light">
                    <tr>
                        <th>交易时间</th>
                        <th>交易类型</th>
                        <th>卡号</th>
                        <th>客户姓名</th>
                        <th class="text-end">金额</th>
                    </tr>
                </thead>
                <tbody>
                    {% for trans in transactions %}
                    <tr>
                        <td>{{ trans.tradeDate.strftime('%Y-%m-%d %H:%M') }}</td>
                        <td>
                            <span class="badge bg-{% if trans.tradeType == '存款' %}success{% else %}warning{% endif %}">
                                {{ trans.tradeType }}
                            </span>
                        </td>
                        <td>{{ trans.cardID }}</td>
                        <td>{{ trans.customerName }}</td>
                        <td class="text-end">¥{{ "%0.2f"|format(trans.tradeMoney) }}</td>
                    </tr>
                    {% else %}
                    <tr>
                        <td colspan="5" class="text-center text-muted">暂无交易记录</td>
                    </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
</div>
{% endblock %}